﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Salon
{
    public partial class FormConnectionConf : Form
    {
        public string ConnectionString;

        public FormConnectionConf()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtServer.Text == "") { MessageBox.Show("Proszępodać nazwę serwera SQLh"); return; }
            if (txtDatabase.Text == "") { MessageBox.Show("Proszępodać nazwę bazy danych"); return; }
            if (txtLogin.Text == "") { MessageBox.Show("Proszępodać login do bazy danych"); return; }
            if (txtPasswd.Text == "") { MessageBox.Show("Proszępodać hasło do bazy danych"); return; }

            ConnectionString = "server=" + txtServer.Text + ";uid=" + txtLogin.Text + ";pwd=" + txtPasswd.Text + ";database=" + txtDatabase.Text + ";MultipleActiveResultSets=True;";


            FileStream fs = new FileStream("connection.txt", FileMode.OpenOrCreate, FileAccess.Write);
            try
            {
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine(ConnectionString);
                sw.Close();
                this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Błąd zapisu danych konfiguracyjnych!");
            }

        }
    }
}
